package com.qingcloud.task.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingcloud.task.mapper.TaskTransferMapper;
import com.qingcloud.task.model.TaskTransfer;
import com.qingcloud.task.service.TaskTransferService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 转派任务记录表 服务实现类
 * </p>
 *
 * @author zhengjibin
 * @since 2022-01-20
 */
@Service
public class TaskTransferServiceImpl extends ServiceImpl<TaskTransferMapper, TaskTransfer> implements TaskTransferService {
    @Resource
    private TaskTransferMapper taskTransferMapper;

    /**
     * 查询任务最新的转派记录
     */
    @Override
    public TaskTransfer selectNewTransfer(Long taskId) {
        QueryWrapper<TaskTransfer> wrapper = new QueryWrapper<>();
        wrapper.eq("task_id",taskId);
        wrapper.orderByDesc("create_time");
        wrapper.last("limit 0,1");
        TaskTransfer transfer = taskTransferMapper.selectOne(wrapper);
        return transfer;
    }

    @Override
    public void save(Long taskId, String userId, String toUserId) {
        TaskTransfer transfer = new TaskTransfer();
        transfer.setTaskId(taskId);
        transfer.setFromUserId(userId);
        transfer.setToUserId(toUserId);
        taskTransferMapper.insert(transfer);
    }
}
